#!/system/bin/sh

#================================================================
#   Copyright (C) 2023 Sangfor Ltd. All rights reserved.
#
#   文件名称：CIS-CentOS7-Benchmark.sh
#   创 建 者：宋耀
#   创建日期：2023年06月30日
#   描    述：CIS_CentOS_Linux_7_Benchmark_v3.1.1- 05-21-2021
#
#================================================================

# 获取脚本所在的绝对路径
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
. ${SCRIPT_DIR}/includes/test_utils.sh
. ${SCRIPT_DIR}/includes/log_utils.sh

func_wrapper() {
  local func=$1
  shift
  local args=$@
  ${func} ${args}
  local result=$?
  if [[ "$result" == "127" ]]; then
    info "${func} not implemented"
  elif [[ "$result" == "0" ]]; then
    access "${func}"
  elif [[ "$result" == "1" ]]; then
    error "${func}"
  elif [[ "$result" == "2" ]]; then
    warn "${func}"
  fi
}

main() {
  info "0代表合规、1代表不合规、2代表不存在该规则"
  . ${SCRIPT_DIR}/rules.sh
  rule_functions=$(grep -oE '^[[:space:]]*[^[:space:]()]+[[:space:]]*\(\)' rules.sh)
  for func in ${rule_functions}; do
    func_name=$(echo "${func}" | awk -F'(' '{print $1}')
    func_wrapper "${func_name}"
  done
}

main "$@"
